package level4Assessment;

import java.util.Calendar;

public class DriveUpParkingTransaction extends ParkingTransaction 
{
	private String registrationNumber;
	private int arrivalHour;
	private int arrivalMinute;
	private static double hoursStaying;
	private int exitTimeHour;
	private int exitTimeMinute;
	private int lengthHour;
	private int lengthMin;
	private double parkingCost;
	Calendar cal = Calendar.getInstance();
	int day = cal.get(Calendar.DAY_OF_WEEK);
	int month = cal.get(Calendar.MONTH);
	int year = cal.get(Calendar.YEAR);

	
	public DriveUpParkingTransaction(String registrationNumber, int arrivalHour, int arrivalMinute, double hoursStaying) 
	{
		this.registrationNumber = registrationNumber;
		this.arrivalHour = arrivalHour;
		this.arrivalMinute = arrivalMinute;
		this.hoursStaying = hoursStaying;

	}

	public double calculateTotalCost()
	{
		hoursStaying = Math.round(hoursStaying);
		
		exitTimeHour = (int) (arrivalHour + Math.round(hoursStaying));
		exitTimeMinute = arrivalMinute;
		lengthHour = exitTimeHour - arrivalHour;
		lengthMin = exitTimeMinute - arrivalMinute;
		
		if(day == 1 || day == 7)
		{
			if(hoursStaying < 2)
			{
				parkingCost = 4.40;
			}else if(hoursStaying < 6 && hoursStaying >= 2)
			{
				parkingCost = 7.40;
			}else if(hoursStaying >= 6 && hoursStaying < 24)
			{
				parkingCost = 12.00;
			}
		}else
		{
			if(hoursStaying < 1)
			{
				parkingCost = 4.70;
			}else if(hoursStaying < 2 && hoursStaying >= 1)
			{
				parkingCost = 7.40;
			}else if(hoursStaying < 4 && hoursStaying >= 2)
			{
				parkingCost = 10.30;
			}else if(hoursStaying < 6 && hoursStaying >= 4)
			{
				parkingCost = 14.80;
			}else if(hoursStaying < 9 && hoursStaying >= 6)
			{
				parkingCost = 17.80;
			}
			else if(hoursStaying < 12 && hoursStaying >= 9)
			{
				parkingCost = 20.20;
			}else if(hoursStaying < 24 && hoursStaying >= 12)
			{
				parkingCost = 23.70;
			}
			
		}
		System.out.println("Here");
		CreditCardValidation newCardValidation = new CreditCardValidation();
		TransactionWriter transactionWriter = new TransactionWriter(transactionNum, registrationNumber, arrivalHour, arrivalMinute, exitTimeHour, 
				exitTimeMinute, lengthHour, lengthMin, parkingCost);
		newCardValidation.ccValidation();
		AuthorisationWriter authorisationWriter = new AuthorisationWriter(transactionNum, 'd', newCardValidation.getCcCardNum(), newCardValidation.getCcExpiryDate(), newCardValidation.isCCValid(), newCardValidation.ccValidation());
			super.displayToTerminal(registrationNumber, hoursStaying, parkingCost);
			transactionNum++;
			return parkingCost;
		}
	}

